package com.ruoyi.special.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.db.mapper.SpecialDataInfoMapper;
import com.ruoyi.db.model.param.SpecialDataParam;
import com.ruoyi.special.service.ISpecialMemberService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static com.ruoyi.common.utils.ShiroUtils.getSysUser;

@Service
@DataSource(DataSourceType.SLAVE)
public class SpecialMemberServiceImpl implements ISpecialMemberService {

    @Resource
    SpecialDataInfoMapper specialDataInfoMapper;

    /**
     *
     * @param specialDataParam
     * @return
     */
    @Override
    public List<Map<String, Object>> getCommonListData(SpecialDataParam specialDataParam) {

        // 根据用户进行判断数据权限
        SysUser user = getSysUser();
        if (!user.isAdmin()){
            if (StrUtil.equals(user.getUserType(), UserConstants.REGISTER_USER_TYPE)){
                specialDataParam.setAdminUserId(user.getUserId());
            }
            specialDataParam.setDeptId(user.getDeptId());
        }

        List<Map<String, Object>> commonListData = specialDataInfoMapper.getCommonListData(specialDataParam);
//        commonListData.stream().forEach(resultMap -> {
//            Long uid = (Long) resultMap.get("uid");
//            resultMap.put("uid", uid+"");
//        });

        return commonListData;
    }

}
